package com.yueyin.ui.main;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yueyin.R;
import com.yueyin.databinding.ActivityDirsBinding;
import com.yueyin.databinding.FragmentCatalogBinding;

import java.util.List;

public class MyAdapter extends BaseAdapter {

    List<Data> dataList;
    Context context;
    FragmentCatalogBinding fragmentCatalogBinding;
    ActivityDirsBinding activityDirsBinding;

    public MyAdapter(Context context, List<Data> dataList, FragmentCatalogBinding fragmentCatalogBinding) {
        this.context = context;
        this.dataList = dataList;
        this.fragmentCatalogBinding = fragmentCatalogBinding;
    }

    public MyAdapter(Context context, List<Data> dataList, ActivityDirsBinding activityDirsBinding) {
        this.context = context;
        this.dataList = dataList;
        this.activityDirsBinding = activityDirsBinding;
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {


        if (fragmentCatalogBinding != null) {
            if (convertView == null) {
                convertView = LayoutInflater.from(context).inflate(R.layout.list_music_item, parent, false);
            }

            TextView tvIndex = convertView.findViewById(R.id.tvIndex);
            tvIndex.setText(String.valueOf(position + 1));

            TextView tvMusicName = convertView.findViewById(R.id.tvMusicName);
            tvMusicName.setText(dataList.get(position).getName());
        }

        if (activityDirsBinding != null) {

            if (convertView == null) {
                convertView = LayoutInflater.from(context).inflate(R.layout.list_dir_item, parent, false);
            }
            //
            TextView textView = convertView.findViewById(R.id.tvDir);
            textView.setText(dataList.get(position).getPath());
        }

        return convertView;
    }


}
